﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using baseSet.importExport;
using dhSystemBLL.produceBLL;
using dhsystem.Main;
using dhDataAcess.baseBLL;

namespace dhsystem.orderForm
{
    public partial class FrmV_cgshrkDetail : Form
    {
        string type;
        public FrmV_cgshrkDetail(string _type)
        {
            InitializeComponent();
            type = _type;
        }
        cgshrkBLL cgshrk = new cgshrkBLL();
        private void FrmV_cgshrkDetail_Load(object sender, EventArgs e)
        {
            if (type == "原材料仓")
            {
                bindingSourcepdrk.DataSource = cgshrk.getV_cgshrkDetailBystocknameNo();
                dGridpdrk.DataSource = bindingSourcepdrk;
                DcolumnSet.colSet(moduleInfo.V_cgshrkDetail, dGridpdrk);
                toolStripStatusLabel1.Text = "数据总条数:" + dGridpdrk.RowCount.ToString() + "条";
            }
            else
            {
                bindingSourcepdrk.DataSource = cgshrk.getV_cgshrkDetailBystockname ();
                dGridpdrk.DataSource = bindingSourcepdrk;
                DcolumnSet.colSet(moduleInfo.V_cgshrkDetail, dGridpdrk);
                toolStripStatusLabel1.Text = "数据总条数:" + dGridpdrk.RowCount.ToString() + "条";
            }
        }

        private void buttupdate_Click(object sender, EventArgs e)
        {
            if (type == "原材料仓")
            {
                bindingSourcepdrk.DataSource = cgshrk.getV_cgshrkDetailBystocknameNo();
                dGridpdrk.DataSource = bindingSourcepdrk;
                DcolumnSet.colSet(moduleInfo.V_cgshrkDetail, dGridpdrk);
                toolStripStatusLabel1.Text = "数据总条数:" + dGridpdrk.RowCount.ToString() + "条";
            }
            else
            {
                bindingSourcepdrk.DataSource = cgshrk.getV_cgshrkDetailBystockname();
                dGridpdrk.DataSource = bindingSourcepdrk;
                DcolumnSet.colSet(moduleInfo.V_cgshrkDetail, dGridpdrk);
                toolStripStatusLabel1.Text = "数据总条数:" + dGridpdrk.RowCount.ToString() + "条";
            }
        }

        private void toolExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void toolQuery_Click(object sender, EventArgs e)
        {
            FrmDataQuery query = new FrmDataQuery(moduleInfo.V_cgshrkDetail);
            DialogResult result = query.ShowDialog();
            if (result == DialogResult.Yes)
            {
                dGridpdrk.DataSource = query.rTable;
            }
        }

        private void toolExport_Click(object sender, EventArgs e)
        {
            FrmExcelExport frm = new FrmExcelExport(moduleInfo.V_cgshrkDetail, dGridpdrk, "出库信息");
            frm.ShowDialog();
        }

        private void dGridpdrk_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {
            decimal count = 0;
            for (int i = 0; i < dGridpdrk.SelectedRows.Count; i++)
            {
                if (dGridpdrk.SelectedRows[i].Cells[dGridpdrk.CurrentCell.ColumnIndex].Value != null)
                {
                    try
                    {
                        count = count + decimal.Parse(dGridpdrk.SelectedRows[i].Cells[dGridpdrk.CurrentCell.ColumnIndex].Value.ToString());
                    }
                    catch (Exception)
                    {
                        continue;//非数字时,会报错,跳过
                    }
                }
            }
            if (count == 0)
            {
                this.textBox1.Text = "";
            }
            else
            {
                this.textBox1.Text = "求和=" + count.ToString();
            }
        }

        private void buttonQuery_Click(object sender, EventArgs e)
        {
            try
            {
                if (type == "原材料仓")
                {
                    bindingSourcepdrk.DataSource = cgshrk.getV_cgshrkDetailBymatNamelikeNo("%" + textMatNameQuery.Text + "%");
                    dGridpdrk.DataSource = bindingSourcepdrk;
                    DcolumnSet.colSet(moduleInfo.V_cgshrkDetail, dGridpdrk);
                    toolStripStatusLabel1.Text = "数据总条数:" + dGridpdrk.RowCount.ToString() + "条";
                }
                else
                {
                    bindingSourcepdrk.DataSource = cgshrk.getV_cgshrkDetailBymatNamelike1("%" + textMatNameQuery.Text + "%");
                    dGridpdrk.DataSource = bindingSourcepdrk;
                    DcolumnSet.colSet(moduleInfo.V_cgshrkDetail, dGridpdrk);
                    toolStripStatusLabel1.Text = "数据总条数:" + dGridpdrk.RowCount.ToString() + "条";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //bindingSourcepdrk.DataSource = basicSql.getV_cgshrkDetail(dateTimePicker1.Value.ToString(), dateTimePicker2.Value.ToString());
            //dGridpdrk.DataSource = bindingSourcepdrk;
            //DcolumnSet.colSet(moduleInfo.V_cgshrkDetail, dGridpdrk);
            //toolStripStatusLabel1.Text = "数据总条数:" + dGridpdrk.RowCount.ToString() + "条";
            try
            {
                if (type == "原材料仓")
                {
                    bindingSourcepdrk.DataSource = basicSql.getV_cgshrkDetail(dateTimePicker1.Value.ToString(), dateTimePicker2.Value.ToString());
                    dGridpdrk.DataSource = bindingSourcepdrk;
                    DcolumnSet.colSet(moduleInfo.V_cgshrkDetail, dGridpdrk);
                    toolStripStatusLabel1.Text = "数据总条数:" + dGridpdrk.RowCount.ToString() + "条";
                }
                else
                {
                    bindingSourcepdrk.DataSource = basicSql.getV_cgshrkDetailwj(dateTimePicker1.Value.ToString(), dateTimePicker2.Value.ToString());
                    dGridpdrk.DataSource = bindingSourcepdrk;
                    DcolumnSet.colSet(moduleInfo.V_cgshrkDetail, dGridpdrk);
                    toolStripStatusLabel1.Text = "数据总条数:" + dGridpdrk.RowCount.ToString() + "条";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
    }
}
